home *** CD-ROM | disk | FTP | other *** search
- /*
- * find_diz.c
- * this finds the file description in the index file.
- *
- */
-
- #include <ctype.h>
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- FILE *logfile;
-
- static void _Cdecl print_err(const char *fmt, ...);
-
- static char copyright[] = "make_diz, Copyright (C) 1994 Walnut Creek CDROM\n";
-
- void _Cdecl
- main(int argc, char *argv[]) {
- FILE *fd;
- FILE *out;
- char buf1[100];
- char buf[2000];
- char *p;
-
- sprintf(buf1, "%s\\wildcat.txt", argv[2]);
-
- if (NULL == (fd = fopen(buf1, "r"))) {
- fprintf(stderr, "Unable to open `%s' on CDROM.\n", buf1);
- exit(1);
- }
-
- p = strrchr(argv[1], '\\') + 1;
-
- while (NULL != fgets(buf, 1998, fd)) {
- if (0 == strncmpi(buf, p, strlen(p))) {
- p = &buf[14];
- while (*p && isspace(*p))
- ++p;
- if (!*p) {
- /* no description in index file */
- fprintf(stderr, "no description in index file |%s|\n",
- &buf[14]);
- exit(1);
- }
-
- if (NULL == (out = fopen("file_id.diz", "wt"))) {
- print_err("erroring opening file_id.diz\n");
- exit(1);
- }
-
- fprintf(out, "%s", &buf[14]);
- fclose(out);
-
- exit(0);
- }
- }
-
- print_err("unable to find `%s' in `%s'\n", p, buf1);
- exit(1);
- }
-
- void _Cdecl
- print_err(const char *fmt, ...) {
- va_list args;
- char str[500];
-
- va_start(args, fmt);
- vsprintf(str, fmt, args);
- va_end(args);
-
- if (NULL == (logfile = fopen("logfile", "at"))) {
- fprintf(stderr, "erroring opening logfile\n");
- exit(1);
- }
-
- fprintf(logfile, "%s", str);
- fclose(logfile);
-
- fprintf(stderr, "%s", str);
- }
-